import org.apache.commons.lang3.StringUtils;
import reactor.core.publisher.Mono;

/**
 * @auther zhouliangliang
 * @date 2022/10/8 23:15
 * @description
 */
public class AsyncDemo {

    private interface Callback{
        void doOnError();
        void doOnSuccess();
    }

    private static class A{
        public void invokeB(String value) {
            AsyncDemo.B b = new AsyncDemo.B();
            b.doSomething(value, new AsyncDemo.Callback() {
                @Override
                public void doOnError() {
                    System.out.println("in class A method doOnError!");
                }

                @Override
                public void doOnSuccess() {
                    System.out.println("in class A method doOnSuccess!");
                }
            });
        }
    }

    private static class B{
        public void doSomething(String value, AsyncDemo.Callback callback) {
            //do something
            try {
                Thread.sleep(3000);
            } catch (Exception e) {
                e.printStackTrace();
            }

            if(StringUtils.isEmpty(value)) {
                callback.doOnError();
            } else {
                callback.doOnSuccess();
            }
        }
    }

    public static void main(String[] args) throws Exception{
        A a = new A();
        a.invokeB("sfsdf");
//        Thread.sleep(5000);
    }
}
